package com.zhitong.ztblog.services.servicesImp;

import com.zhitong.ztblog.entity.Label;
import com.zhitong.ztblog.mappers.LabelMapper;
import com.zhitong.ztblog.services.ILabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LabelService implements ILabelService {

    @Autowired
    private LabelMapper labelMapper;

    @Override
    public Label[] findAll() {
        Label[] all = labelMapper.findAll();
        return all;
    }

    @Override
    public Label findById(int id) {
        Label label = labelMapper.findById(id);
        return label;
    }

    @Override
    public Label[] findByBid(int bid) {
        Label[] labels = labelMapper.findByBid(bid);
        return labels;
    }

    @Override
    public Label[] findByRand() {
        Label[] labels = labelMapper.findByRand();
        return labels;
    }

    @Override
    public int findLabelNum() {
        int num = labelMapper.findLabelNum();
        return num;
    }

    @Override
    public int findBlogNumByLid(int lid) {
        int num = labelMapper.findBlogNumByLid(lid);

        return num;
    }

    @Override
    public void delLabelById(int id) {
        labelMapper.delLabelById(id);
    }

    @Override
    public void insertLabel(Label label) {
        labelMapper.insertLabel(label.getName());
    }

    @Override
    public int findLabelNumByName(Label label) {
        int count = labelMapper.findLabelNumByName(label.getName());
        return count;
    }

    @Override
    public Label findLabelByName(String name) {
        Label labelByName = labelMapper.findLabelByName(name);
        return labelByName;
    }
    

    @Override
    public void bInsertLabelByName(int uid, String name) {
        Label labelByName = labelMapper.findLabelByName(name);
         labelMapper.bInsertLabelById(uid, labelByName.getId());
    }

    @Override
    public String[] findNamesByBid(int bid) {
        String[] names = labelMapper.findNamesByBid(bid);
        return names;
    }

    @Override
    public void deleteByBid(int bid) {
        labelMapper.deleteByBid(bid);
    }
}
